package mysql

import "gorm.io/gorm"

type Users struct {
	gorm.Model
	Tel      string `json:"tel" gorm:"type:char(11);not null;unique;comment:'手机号'"`
	Password string `json:"password" gorm:"type:char(32);not null;comment:'密码'"`
}

type RealNames struct {
	gorm.Model
	UserId   int    `json:"userId" gorm:"type:int(10);not null;comment:'用户编号'"`
	RealName string `json:"realName" gorm:"type:varchar(20);not null;comment:'真实姓名'"`
	IdCard   string `json:"idCard" gorm:"type:char(18);not null;comment:'身份证号'"`
}

func (u *Users) Register() error {
	return DB.Model(&Users{}).Create(&u).Error
}

func Login(tel string) (user *Users, err error) {
	err = DB.Model(&Users{}).Where("tel=?", tel).Limit(1).Find(&user).Error
	return
}

func (r *RealNames) CreateReal() error {
	return DB.Debug().Model(&RealNames{}).Create(&r).Error
}
